﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App1
{
    class Guard: Pieces
    {
        public override bool CheckLegalMove(int row, int col)
        {
            bool legal = false;
            //Side 1
            if (Side == 1)
            {
                if (row < 3 && (2 < col && col < 6))
                    if (Math.Abs(row - _row) == 1 && Math.Abs(col - _col) == 1)
                    {
                        if (!Board.Square[row, col].State)
                            legal = true;
                        else
                            if (Board.Square[row, col].Side != _side)
                                legal = true;
                    }
            }
            //Side 2
            if (_side == 2)
            {
                if (row > 6 && (2 < col && col < 6))
                    if (Math.Abs(row - _row) == 1 && Math.Abs(col - _col) == 1)
                    {
                        if (!Board.Square[row, col].State)
                            legal = true;
                        else
                            if (Board.Square[row, col].Side != _side)
                                legal = true;
                    }
            }

            if (GameChess.Player[0].King.Col == GameChess.Player[1].King.Col
                && _col == GameChess.Player[1].King.Col)
            {
                int n = 0;
                if (col != _col)
                {
                    GameChess.MakeEmptySquare(_row, _col);
                    for (int i = GameChess.Player[0].King.Row + 1; i < GameChess.Player[1].King.Row; ++i)
                        if (Board.Square[i, _col].State)
                            ++n;
                    if (n == 0)
                        legal = false;
                    Board.Init(_row, _col, _name, _value, _side, true);
                }
            }
            return legal;
        }

        public override bool CheckSafeOfKing(int row, int col)
        {
            return true;
        }
    }
}
